/**
 * @ author kunnisser
 * @ date 2018/3/14
 * @ description: 设置mock数据接口
 */

import Axios from 'axios';
import qs from 'qs';

const TIMEOUT = 30e3;
const FILETIMEOUT = 60e3;
const DevApiDomain = 'http://oms.k8s.star-charge.com';
const ProApiDomain = 'https://oms-console.starcharge.com';

const getMock = (url) => {
    return (params) => {
        return Axios.get(url, {
        params,
        timeout: TIMEOUT,
        headers: {
            'Authorization': window.sessionStorage.getItem('token')
        }
    })
}
}

const postMock = (url) => {
    return (params) => {
       return Axios.post(url, qs.stringify(params), {
        timeout: TIMEOUT,
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Authorization': window.sessionStorage.getItem('token')
        }
    });
    }
}

const fileMock = (url) => {
    return (params) => {
        return Axios.post(url, qs.stringify(params), {
            timeout: FILETIMEOUT,
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        });
    }
}

// v1.0.1 api
const buildApi = process.env.doingType === 'buildDev' ? DevApiDomain : ProApiDomain;
const Prefix = process.env.NODE_ENV === 'production' ? buildApi + '/api' : '/api';

const getUserMenuList = getMock(Prefix + '/user/userMenuList');
const getPermissionList = getMock(Prefix + '/right/permissionList');
const editPermission = postMock(Prefix + '/right/editPermission');
const deletePermission = postMock(Prefix + '/right/delPermission');
const getSmsGroupList = getMock(Prefix + '/sms/getSmsGroupList');
const getSmsInfoList = getMock(Prefix + '/sms/getSmsInfoList');
const getRoleList = getMock(Prefix + '/right/roleList');
const editRole = postMock(Prefix + '/right/editRole');
const deleteRole = postMock(Prefix + '/right/delRole');
const addSmsGroupInfo = postMock(Prefix + '/sms/addSmsGroupInfo');
const sendSmsByGroupId = postMock(Prefix + '/sms/sendSmsByGroupId');
const getUserList = getMock(Prefix + '/user/userList');
const getDDuserList = getMock(Prefix + '/user/ddUserList');
const addUser = postMock(Prefix + '/user/addUser');
const distributeRole = postMock(Prefix + '/right/distributeRole');

// v1.1.0 api
const exchangeCode = postMock(Prefix + '/scUser/userIdAndPhoneChange');
const fetchMap = getMock(Prefix + '/station/findStubGroupList');
const chargingApplication = postMock(Prefix + '/scUser/chargingApplication');
const processChargeNumApply = postMock(Prefix + '/scUser/processChargeNumApply');
const errorCorrection = postMock(Prefix + '/station/errorCorrection');
const estimateManagment = postMock(Prefix + '/interaction/estimateManagment');
const buildingApply = postMock(Prefix + '/station/buildingApply');
const processed = postMock(Prefix + '/station/processed');
const deleteCommend = postMock(Prefix + '/interaction/delete');
const replyCommend = postMock(Prefix + '/interaction/reply');
// 电桩列表查询
const findStubList = postMock(Prefix + '/station/findStubList');
// 私桩列表查询
const findPrivateStubList = postMock(Prefix + '/station/findPrivateStubList');
// 订单列表
const findOrderList = postMock(Prefix + '/order/findOrderList');
// 订单详情
const getOrderDetail = postMock(Prefix + '/order/getOrderDetail');
// 电站详情
const getStubGroupDetail = postMock(Prefix + '/station/getStubGroupDetail');
// 用户详情
const getUserInfo = postMock(Prefix + '/scUser/getUserInfo');
// 用户积分列表
const getUserIntergration = postMock(Prefix + '/scUser/getUserIntergration');
// 碳账户明细
const getUserCarbonInfo = postMock(Prefix + '/scUser/getUserCarbonInfo');
// 用户账户明细
const accountDetail = postMock(Prefix + '/scUser/accountDetail');
// 星币转换
const starCoinTransfer = postMock(Prefix + '/scUser/starCoinTransfer');
// 用户抵用券信息
const voucherList = postMock(Prefix + '/scUser/voucherList');
// 企业信息
const companyInfo = postMock(Prefix + '/scUser/companyInfo');
// 初始开票汇总信息
const inVoiceSummary = postMock(Prefix + '/invoice/summary');
// 申请开票
const applyInvoice = postMock(Prefix + '/invoice/apply');
// 发票列表
const invoiceList = postMock(Prefix + '/invoice/list');
// 发票详情
const invoiceInfo = postMock(Prefix + '/invoice/info');
// 过程数据
const processData = postMock(Prefix + '/order/processData');
// 企业密码重置
const companyInitPwd = postMock(Prefix + '/scUser/companyInitPwd');
// 阿里云日志列表
const aliLoglist = postMock(Prefix + '/log/aliGetLogs');
// 阿里云日志store
const alilogStore = getMock(Prefix + '/log/aliListLogstore');

// v1.2.0 api
// 私桩管理列表
const privateStubManager = postMock(Prefix + '/station/privateStubManager');
// 私桩类型列表
const privateTypeList = postMock(Prefix + '/station/privateType');

// 绑定邮箱地址接口
const invoiceSend = postMock(Prefix + '/invoice/invoiceSend');

export {
  getUserMenuList,
  getPermissionList,
  editPermission,
  deletePermission,
  getSmsGroupList,
  getSmsInfoList,
  getRoleList,
  editRole,
  deleteRole,
  addSmsGroupInfo,
  sendSmsByGroupId,
  getUserList,
  getDDuserList,
  addUser,
  distributeRole,
  exchangeCode,
  fetchMap,
  chargingApplication,
  processChargeNumApply,
  errorCorrection,
  estimateManagment,
  buildingApply,
  processed,
  deleteCommend,
  replyCommend,
  findStubList,
  findPrivateStubList,
  findOrderList,
  getOrderDetail,
  getStubGroupDetail,
  getUserInfo,
  getUserIntergration,
  getUserCarbonInfo,
  accountDetail,
  starCoinTransfer,
  voucherList,
  companyInfo,
  inVoiceSummary,
  applyInvoice,
  invoiceList,
  invoiceInfo,
  processData,
  companyInitPwd,
  aliLoglist,
  alilogStore,
  privateStubManager,
  privateTypeList,
  invoiceSend
}
